package cn.lzk._04_delay;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.Date;

public class Producer {
    public static void main(String[] args) throws Exception {
        //创建生产者
        DefaultMQProducer producer = new DefaultMQProducer("delay_producer");
        //设置nameserver地址
        producer.setNamesrvAddr("localhost:9876");
        //启动生产者
        producer.start();
        //创建消息
        Message message = new Message("delay", "hello", "我在源码学习java".getBytes(StandardCharsets.UTF_8));
        //设置延时等级
        message.setDelayTimeLevel(3);
        //发送消息
        producer.send(message);
        System.out.println(new Date().toLocaleString());
        //关闭生产者
        producer.shutdown();
    }
}
